
#include "base/persistance.h"
#include "base/persistent_data.h"

namespace test_suite_persistance
{

class Object
{
public:
	Object() : i(0) { }
	Object(int ii) : i(ii) { }
	int i;
};

TEST(test_base, managed_memory)
{
	ManagedMemory::NewInstance(boost::interprocess::open_or_create, "shared_memory", 1 * 1024 * 1024);

	void *ptr = ManagedMemory::Instance().allocate(100);
	EXPECT_TRUE(ptr != NULL);

	ManagedMemory::type_t::handle_t handle =
		ManagedMemory::Instance().get_handle_from_address(ptr);
	void *ptr2 = ManagedMemory::Instance().get_address_from_handle(handle);
	EXPECT_TRUE(ptr == ptr2);

	ManagedMemory::Instance().deallocate(ptr);

	Object *p = ManagedMemory::Instance().construct<Object>(boost::interprocess::anonymous_instance)();
	EXPECT_TRUE(p != NULL);
	EXPECT_EQ(p->i, 0);
	ManagedMemory::Instance().destroy_ptr(p);

	p = ManagedMemory::Instance().construct<Object>(boost::interprocess::anonymous_instance)(10);
	EXPECT_TRUE(p != NULL);
	EXPECT_EQ(p->i, 10);
	ManagedMemory::Instance().destroy_ptr(p);
}

class MyData : public PersistentData
{
public:
	int i;
	double d;
};

TEST(test_base, persistent_data)
{
	MyData *p = new MyData();
	EXPECT_TRUE(p != NULL);
}

TEST(test_base, persistent_data_manager)
{

}

}
